menusectionbox: Improve circular button spacing
authorMatthias Clasen <mclasen@redhat.com>
Thu, 23 Apr 2020 02:16:46 +0000 (22:16 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 23 Apr 2020 02:16:46 +0000 (22:16 -0400)
In the n == 2 case, we want to avoid the buttons being
drawn all the way out to the ends of the box, but in the
n >= 3 case, that is exactly what we want for the first
and last button.

gtk/gtkmenusectionbox.c

index 413789a274473f7867b1f1df95dcec455731a261..e6a55fae559799fc240f6f20c1baa6a0c9a9fc1c 100644 (file)
@@ -393,6 +393,26 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
       gtk_box_reorder_child_after (GTK_BOX (box->item_box), widget, sibling);
     }
 
+  if (box->circular)
+    {
+      GtkWidget *c1, *c2, *c3;
+
+      /* special-case the n > 2 case */
+      c1 = gtk_widget_get_first_child (GTK_WIDGET (box->item_box));
+      if ((c2 = gtk_widget_get_next_sibling (c1)) != NULL &&
+          (c3 = gtk_widget_get_next_sibling (c2)) != NULL)
+        {
+          gtk_widget_set_halign (c1, GTK_ALIGN_START);
+          while (c3 != NULL)
+            {
+              gtk_widget_set_halign (c2, GTK_ALIGN_CENTER);
+              c2 = c3;
+              c3 = gtk_widget_get_next_sibling (c3);
+            }
+          gtk_widget_set_halign (c2, GTK_ALIGN_END);
+        }
+    }
+
   gtk_menu_section_box_schedule_separator_sync (box);
 }